package main.java.person.fjsp.algorithm.ga.entity;

import java.util.Objects;
import java.util.UUID;

/**
 * 遗传算法的个体
 * @author xcy
 */
public class Individual {
    /**
     * cs编码
     */
    private int[] csCode;
    /**
     * os编码
     */
    private int[] osCode;
    /**
     * 个体的适应值
     */
    private double fitness;
    /**
     * 该个体的唯一标识
     */
    private final String uuid= UUID.randomUUID().toString();

    public Individual(int[] csCode, int[] osCode) {
        this.csCode = csCode;
        this.osCode = osCode;
    }

    public Individual clone(){
        Individual clone = new Individual(this.csCode.clone(), this.osCode.clone());
        clone.setFitness(this.fitness);
        return clone;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Individual that = (Individual) o;
        return Objects.equals(uuid, that.uuid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uuid);
    }

    public int[] getCsCode() {
        return csCode;
    }

    public void setCsCode(int[] csCode) {
        this.csCode = csCode;
    }

    public int[] getOsCode() {
        return osCode;
    }

    public void setOsCode(int[] osCode) {
        this.osCode = osCode;
    }

    public double getFitness() {
        return fitness;
    }

    public void setFitness(double fitness) {
        this.fitness = fitness;
    }

    public String getUuid() {
        return uuid;
    }


}
